import { ref } from 'vue'
import { defineStore } from 'pinia'
import routes from '@/router/my-routes'

const transformRoutes = routes => {
  const mapRoutes = routeArr => {
    const arr = []
    routeArr.forEach(item => {
      const { path, name, children = [], meta = {} } = item
      arr.push({
        path,
        name,
        meta,
        children: mapRoutes(children)
      })
    })
    return arr
  }
  return mapRoutes(routes)
}

export const useMenuStore = defineStore('menu', () => {
  const menuList = ref([])
  const getMenuList = () => {
    menuList.value = transformRoutes(routes)
    console.log('---[menu store]---', menuList.value)
  }
  getMenuList()
  return {
    menuList,
    getMenuList,
  }
})
